package com.xixiake.immersive;

import android.app.Activity;
import android.view.Window;

/**
 * Created by c-wanghengli on 2017/4/3.
 */
public class SystemBarCompact {

    private boolean mDrawStatus = true;
    private int mStatusBarColor = 0x000000;
    private int mPendingStatusBarColor;
    private Window mWindow;
    private SystemBarTintManager mSystemBarTintManager;


    public SystemBarCompact(Activity activity,boolean drawStatus,int statusBarColor){
        this.mWindow = activity.getWindow();
        this.mPendingStatusBarColor = statusBarColor;
        this.mDrawStatus = drawStatus;
    }

    public void init() {
        if(ImmersiveUtil.isSupportImmersive() == 1){
            ensureTintManager();
            mSystemBarTintManager.setStatusBarTintEnabled(mDrawStatus);
        }
        setStatusBarColor(this.mPendingStatusBarColor);
    }

    private void ensureTintManager() {
        if(mSystemBarTintManager == null){
            mSystemBarTintManager = new SystemBarTintManager(mWindow,mDrawStatus);
        }
    }

    private void setStatusBarColor(int color) {
        if(mDrawStatus && mStatusBarColor != color){
            mStatusBarColor = color;
            if(mSystemBarTintManager != null && ImmersiveUtil.isSupportImmersive() ==1){
                mSystemBarTintManager.setStatusBarTintColor(color);
            }
        }
    }
}
